<?php

/*
// @author : lael
// blog : http://hi.baidu.com/lael80
// http://www.gzyd.net
// all right reserved.
*/

namespace ydsdk\controllers\admin;

class device extends \ydsdk\core\admin {
	public function __construct(){
		parent::__construct();
		if($_SESSION['admin']['type'] != 2)show_message('没有访问权限', siteurl('con=admin/index'));
	}

	public function index(){
		$list = $this->db->get_page('deerxi_device', '*', 'admin_id='.$_SESSION['admin']['admin_id'].' order by id desc', false, $_GET['page'], $_GET['pagesize']?:20);
		$this->smarty->assign('list', $list);
		$this->smarty->display('device/index.html');
	}
	
	public function edit(){
		if(issubmit()){
			$data = $this->formdata('deerxi_device');
			if($_GET['id']){
				$this->db->update('deerxi_device', $data, "admin_id=".$_SESSION['admin']['admin_id']." and id=".$_GET['id']);
			}else{
				$data['admin_id'] = $_SESSION['admin']['admin_id'];
				$data['banktime'] = formattime(time());
				$this->db->insert('deerxi_device', $data);
			}
			exitjson(1);
		}
		if($_GET['id']){
			$row = $this->db->get_row('deerxi_device', '*', array('admin_id' => $_SESSION['admin']['admin_id'], 'id' => $_GET['id']));
			if(!$row)show_message('数据不存在');
			$this->smarty->assign('row', $row);	
		}
		$this->smarty->display('device/edit.html');	
	}
	
	public function delete(){
		if(!empty($_POST['ids'])){
			$this->db->delete('deerxi_device', 'admin_id='.$_SESSION['admin']['admin_id'].' and id in ('.$_POST['ids'].')');	
		}
		exitjson(1);	
	}
}
